#include "sdkconfig.h"

#include <stdio.h>
#include <cmath>
#include <vector>
#include <atomic>
#include <functional>
#include <algorithm>

#include <nvs.h>
#include <nvs_flash.h>

#include <esp_log.h>
#include <esp_err.h>
#include <esp_timer.h>
#include <esp_heap_caps.h>
#include <esp_event.h>
#include <esp_system.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"

#include "app.h"
#include "driver/i2c_master.h"
#define TAG "MAIN"

extern "C" void app_main(void)
{
    ESP_ERROR_CHECK(esp_event_loop_create_default());

    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    // 启动App实例（这会启动主循环）
    ESP_LOGI(TAG, "启动App实例...");
    App::GetInstance().Start();
}
